const mongoose=require("mongoose");
mongoose.connect("mongodb://localhost/test");
mongoose.Promise=Promise;

const Schema=mongoose.Schema({
  name:String,
  age:Number
});

const User=mongoose.model("User",Schema);

    async function run(){
    await User.remove();
    await User.create([
       {name:"kaka",age:111},
       {name:"kaka",age:333},
       {name:"kaka",age:092},
       {name:"mm",age:123}
     ]);
     //这里不能调用方法fine();因为这里要返回的是一个对象，而不是一个数组
     var u1=await User.findOne({name:"kaka"});
     console.log(u1);
     u1.age=666;
     await u1.save();
    console.log(await User.findById(u1.id));

    await User.update({name:"kaka"},{age:35},{multi:true});
          console.log(await User.find({name:"kaka"}));
    }

run();
